<?php
    header("content-type:text/html;charset=utf-8");
    $config = include_once('../../public/config/config.php');
    include_once('../../public/func/db.php');
    include_once('../../public/func/shangchuan.func.php');
    $table = 'user';
    $filename = '../../public/upload';
    $post = $_POST;
    $post['ctime'] = time();
    $post['pic'] = shangchuan($_FILES['pic'],$filename);
    if($post['pic'] == '没有文件被上传'){
        $post['pic'] = $post['apic'];
    }
    $unamepattern = "/\w/";
    $emailpattern = "/^\w+(\.\w+)*@\w+(\.\w+)+$/";
    if(empty($post['nicname'])){
        die('<script>alert("昵称不能为空");window.location.href="updateuser.php?id='.$_POST['id'].'"
              </script>');
    }else if(!preg_match($unamepattern,$post['uname'])){
        die('<script>alert("用户名不符合数据类型");window.location.href="updateuser.php?id='.$_POST['id'].'"
              </script>');
    }else if(empty($post['sex'])){
        die('<script>alert("性别不能为空");window.location.href="updateuser.php?id='.$_POST['id'].'"
              </script>');
    }else if(!preg_match($emailpattern,$post['email'])){
        die('<script>alert("邮箱不符合数据类型");window.location.href="updateuser.php?id='.$_POST['id'].'"
              </script>');
    }
    $res = update($config,$table,$post);
    if(empty($res)){
        echo "<script>alert('更改成功');window.location.href='user.php'</script>";
    }else{
        echo '<script>alert("更改失败");window.location.href="updateuser.php?id='.$_POST['id'].'"
              </script>';
    }
?>